<template>
  <div class="json-container">
    <div class="mb20 lh1">拼接结构体</div>
    <div class="g6 mb20">
      <span>请定义一个返回值为对象的函数,异步函数建议使用async的方式</span>
    </div>
    <div class="ks-row-middle mb20 lh1">
      <el-input
        type="textarea"
        v-model="text"
        style="width: 100%"
        :autosize="{ minRows: 10}"
        placeholder=""
      />
    </div>
  </div>
</template>

<script>

export default {
  name: 'JsonGenerate',
  props: {
    eventItem: {}, // 需要逻辑编排的对象
    componentItem: {},
    block: {},
    workspace: {}
  },
  components: { },
  computed: {
    text: {
      get() {
        let res = decodeURIComponent(this.defaultFunc)
        const field = this.block?.getField('CODE')
        if(this.block.getFieldValue('CODE')) {
          res = decodeURIComponent(this.block.getFieldValue('CODE'))
        }
        return res
      },
      set(val) {
        const formatStr = encodeURIComponent(val)
        this.block.setFieldValue(formatStr,'CODE')
      }
    }
  },
  data () {
    return {
      defaultFunc : `async ()=>{
      return {}
  }`
    }
  },
  watch: {
    'block': {
      handler() {
        this.getBlockData()
      },
      immediate: true
    }
  },
  methods: {
    getBlockData(){

    }
  }
}
</script>

<style >
 .json-container #monacojs .monaco-scrollable-element {
  left: 0px !important;
   width: 100% !important;
   border: 1px solid #ccc
}

</style>
